unit Unit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm2 = class(TForm)
    Button1: TButton;
    GroupBox1: TGroupBox;
    Edit1: TEdit;
    Label1: TLabel;
    Button2: TButton;
    Edit2: TEdit;
    Button3: TButton;
    Label2: TLabel;
    OpenDialog1: TOpenDialog;
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;
  Dir: String;

implementation

uses Unit1;

{$R *.dfm}

procedure TForm2.Button1Click(Sender: TObject);
begin
  Close;
end;

procedure TForm2.Button2Click(Sender: TObject);
begin
  //Check string..
  if FileExists(Edit2.Text) and not FileExists(Dir+'CKeys\'+Edit1.Text) then
  begin
    //Check file..
    CopyFile(PChar(Edit2.Text),PChar(Dir+'CKeys\'+Edit1.Text),True);
    ShowMessage('Successfully imported!');
    Form1.lvRepaint;
  end
  else
    beep();
  //1.Check Random string to be correct for cUID. Reccomended length: 16-63 chars;
  //2.Check the file
  //3.Import file to folder and register
end;

procedure TForm2.Button3Click(Sender: TObject);
begin
  if OpenDialog1.Execute then Edit2.Text:=OpenDialog1.FileName;
end;

procedure TForm2.FormCreate(Sender: TObject);
begin
  Dir:=ExtractFilePath(paramstr(0));
  //1.Gen random string, which differs from already existing cUIDs.
end;

procedure TForm2.FormShow(Sender: TObject);
var
  a: array [0..63] of Char;
  i: Integer;
const
  chars = 'QWERTYUIOPASDFGHJKLZXCVBNM1234567890';
begin
  randomize;
  for i:= 0 to 62 do
    a[i]:= chars[random(36)+1];
  a[63]:=#0;
  Edit1.Text:=a;
end;

end.
